<template>
  <view class="content">
    <u-form :model="form" ref="form1">
        <u-form-item label="昵称" prop="contact" label-width="auto">
        <u-input v-model="form.nickname"/>
      </u-form-item>
      <u-form-item label="联系方式" prop="contact" label-width="auto">
        <u-input v-model="form.contact"/>
      </u-form-item>

    </u-form>
    <u-button @click="save">保存</u-button>

    <u-button @click="out">退出登录</u-button>
  </view>
  <!--  <tabbar :currentTab='2'/>-->

</template>

<script>

import Tabbar from "@/components/tabbar/index.vue";
import {removeToken, setToken} from "@/common/auth";
import {userRegisterApi, userUpdateApi} from "@/network/api/api";

export default {
  components: {Tabbar},
  data() {
    return {
      title: 'Hello',
      captcha: '',
      form: {
        password: '',
        username: '',
        contact: '',
        nickname: '',
      },
      rules: {
        username: [
          {required: true, message: '请输入合法用户名', trigger: ['change', 'blur'], pattern: "^[a-zA-Z0-9]{4,10}$"}],
        password: [
          {required: true, message: '请输入密码', trigger: ['change', 'blur'], pattern: "^[a-zA-Z0-9]{4,10}$"}]
      }
    }
  },
  onLoad() {

  },
  methods: {
    out() {
      removeToken()
      uni.redirectTo({
        url: '/pages/login/login'
      });
    },
    save() {
      const _this = this
      userUpdateApi(this.form).then(res => {
        if (res.code === 200) {
          uni.showToast({
            title: res.message,
            icon: 'none'
          });
          _this.toLogin()
        } else {
          uni.showToast({
            title: res.message,
            icon: 'none'
          });
        }
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style>
.content {
  text-align: center;
  height: 400upx;
  margin-top: 200upx;
}
</style>
